<?php
namespace App\Services\Main;

use App\Repositories\Main\MsgSysReadRepository;
use App\Repositories\Main\MsgSysRepository;

class MsgSysService
{
    private $service;
    private $read;

    public function __construct()
    {
        $this->service = new MsgSysRepository();
        $this->read = new MsgSysReadRepository();
    }

    public function getAdminIndex()
    {
        return $this->service->getAdminIndex();
    }

    public function getIndex()
    {
        $models = $this->service->getIndexList();
        if (!count($models)) { return ''; }
        $dataArr = array();
        foreach ($models as $k=>$model) {
            $dataArr[$k]['id'] = $model->id;
            $dataArr[$k]['title'] = $model->title;
            $dataArr[$k]['createTime'] = date('Y-m-d',$model->created_at);
            if (time()-3600*24*7 < $model->created_at) { //一周内为最新
                $dataArr[$k]['statusName'] = '最新';
            } else {
                $dataArr[$k]['statusName'] = '';
            }
        }
        return $dataArr;
    }

    public function add($data)
    {
        return $this->service->setAdd($data);
    }

    public function getOne($id)
    {
        $model = $this->service->getShowOne($id);
        return array(
            'title' => $model->title,
            'detail' => $model->detail,
            'createTime' => date('Y-m-d',$model->created_at),
        );
    }

    public function setReadModify($msgSysId,$uid)
    {
        return $this->read->setModifyRead($msgSysId,$uid);
    }
}